package com.beiing.tianshuai.tianshuai.dongtai.model;

import com.beiing.tianshuai.tianshuai.dongtai.CallBack;
import com.beiing.tianshuai.tianshuai.entity.DynamicAddReplyBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicDeleteBean;
import com.beiing.tianshuai.tianshuai.entity.DynamicRelayDetailBean;
import com.beiing.tianshuai.tianshuai.network.DataManager;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by magikliu on 2017/8/25.
 */

public class CommentRelayReplyModel implements CommentRelayReplyModelImpl {

    @Override
    public void addReply(String rid, String cid, String form_uid, String to_uid, String content, String registration_id, final CallBack callBack) {
        DisposableObserver<DynamicAddReplyBean> observer = new DisposableObserver<DynamicAddReplyBean>() {
            @Override
            public void onNext(@NonNull DynamicAddReplyBean dynamicAddReplyBean) {
                callBack.result(dynamicAddReplyBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getAddRelayReplyResult(rid, cid, form_uid, to_uid, content, registration_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void getReply(String id, String uid, final CallBack callBack) {
        DisposableObserver<DynamicRelayDetailBean> observer = new DisposableObserver<DynamicRelayDetailBean>() {
            @Override
            public void onNext(@NonNull DynamicRelayDetailBean relayDetailBean) {
                callBack.result(relayDetailBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };
        DataManager.getDynamicRelayDetail(id, uid, 0, 1, 10)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    @Override
    public void deleteReply(String uid, String id, final CallBack callBack) {
        DisposableObserver<DynamicDeleteBean> observer = new DisposableObserver<DynamicDeleteBean>() {
            @Override
            public void onNext(@NonNull DynamicDeleteBean dynamicDeleteBean) {
                callBack.result(dynamicDeleteBean);
            }

            @Override
            public void onError(@NonNull Throwable e) {
                callBack.error(e);
            }

            @Override
            public void onComplete() {

            }
        };

        DataManager.getRelayReplyDeleteResult(uid, id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
